home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Pascal Super Library
/
Pascal Super Library (CW International)(1997).bin
/
PARSER
/
KPARS_00
/
FPARSER.DOC
next >
Wrap
Text File
|
1993-09-02
|
6KB
|
149 lines
FPARSER (UNIT) LIBRARY REFERENCE
===========================================================================
---------------------------------------------------------------------------
Version - 0.00
File - FPARSER.PAS
Copyright - None. Public Domain.
Author - Keith S. Brown (except where otherwise noted)
Surface mail: Email:(brown@smd4.jsc.nasa.gov)
K.Brown
Code:NASA/JSC/ES64
Houston, TX 77058 (USA) Voice:713-483-8952
Purpose - 1. Translate an infix expression to tokenized RPN.
2. Execute a tokenized RPN expression.
Language - Borland International's Turbo Pascal V:4.x+ for MS-DOS
Remarks - Handles standard Pascal computational assignment expressions.
With some differences, ie.:
■ as per Ada, numeric values may contain embedded underscores.
■ only the first 63 characters of an identifier are significant
■ the semi-colon terminating an expression is optional.
■ the extended unary functions "ArcCos", "ArcSin", "Log"
(base 10), "Sign", "Step", "Tan" are available as well as
the standard Pascal unary functions "Abs", "ArcTan", "Cos",
"Exp", "Ln", "Round", "Sin", "Sqr", "Sqrt", "Trunc".
■ the extended binary operators "^" (as in x^3, cube of x) are
available as well as the standard Pascal binary operators
of "+", "-", "*", "/", "DIV", and "MOD".
■ the extended trinary functions:
"Gate(x,cntr,wide:REAL):REAL;" (rectangular pulse),
"Gaus(x,cntr,variance:REAL):REAL;" (Gaussian pulse),
"Sinc(x,cntr,wide:REAL):REAL;" (Sin(πƒx)/(πƒx)) and
"Tri(x,cntr,wide:REAL):REAL;" (Triangular pulse)
are available.
■ The constants "Pi" (3.1415...) and "e" (2.7182...) are predefined.
■ the assignment of the result to a variable is optional.
However, if no assignment is made, use EvaluatePostfix
instead of ExecutePostfix.
Requires - Turbo Power Professional's TPSTRING unit --> basic string handling
(requires proc/functs: DisposeString, LeftPad, Str2Real, StringFromHeap, StringToHeap)
KSTRING.PAS --> extended string handling
KMATH.PAS --> math functions
Example:
BEGIN
InitSymbolTable;
DefineParameter('y',30.0);
DefineParameter('x',0);
IF TranslateToPostfix('x := Sin(y*Pi/180);') THEN
IF ExecutePostFix THEN
WriteLn('Result = ',ViewParameter('x'));
END;
Example:
VAR
x : REAL;
BEGIN
InitSymbolTable;
DefineParameter('y',30.0);
IF TranslateToPostfix('Sin(y*Pi/180);') THEN
IF EvaluatePostFix(x) THEN
WriteLn('Result = ',x);
END;
Reference - Data Structures & Program Design, Robert L. Kruse
(Chptr 8: The Polish Notation) pp311-355
Revised - 1991.0618 (KSB) Converted from GF and made a unit.
- 1993.0901 (KSB) Updated documentation.
---------------------------------------------------------------------------
===========================================================================
DefineParameter procedure
---------------------------------------------------------------------------
Purpose - If S is not defined add it with its value V to the symbol
table. If it is found, change its value to V.
Declaration - procedure DefineParameter(s:STRING; v:REAL);
---------------------------------------------------------------------------
===========================================================================
EvaluatePostfix function
---------------------------------------------------------------------------
Purpose - Interpret a RPN expression when the result is not assigned
to a variable.
Declaration - function EvaluatePostfix(VAR x:REAL):BOOLEAN;
---------------------------------------------------------------------------
===========================================================================
ExecutePostfix function
---------------------------------------------------------------------------
Purpose - Interpret a RPN expression.
Declaration - function ExecutePostfix:BOOLEAN;
---------------------------------------------------------------------------
===========================================================================
InitSymbolTable procedure
---------------------------------------------------------------------------
Purpose - Initialize the defaults in the symbol table.
Declaration - procedure InitSymbolTable.
Remarks - Must be called first to initialize symbols and operators.
---------------------------------------------------------------------------
===========================================================================
TranslateToPostfix function
---------------------------------------------------------------------------
Purpose - Translate an infix expression to RPN.
Declaration - function TranslateToPostfix(s:STRING):BOOLEAN;
Remarks - The infix expression is first tokenized. However, all
identifiers must be previously declared.
---------------------------------------------------------------------------
===========================================================================
ViewParameter function
---------------------------------------------------------------------------
Purpose - If S is not defined display an error message. If it is
found, return its value.
Declaration - function ViewParameter(s:STRING):REAL;
---------------------------------------------------------------------------